package com.bw.kylin1705f.web;


import com.alibaba.fastjson.JSON;
import com.bw.kylin1705f.entity.Menu;
import com.bw.kylin1705f.service.IMenuService;
import com.bw.kylin1705f.vo.MenuVo;
import com.bw.kylin1705f.vo.ResultEntity;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.Authentication;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author Mht
 * @since 2019-12-05
 */
@RestController
    @RequestMapping("/menu")
@Slf4j
public class MenuController {


    @Autowired
    IMenuService menuService;

    @RequestMapping(value = "/getMenuListByRid",method = RequestMethod.GET)
    public ResultEntity getMenuListByRid(Integer rid){
        List<Integer> menuListByRid = menuService.getMenuListByRid(rid);
        return  ResultEntity.ok(menuListByRid);
    }

    @RequestMapping(value = "/getMenuList",method = RequestMethod.GET)
    public ResultEntity getMeunList(){
        List<MenuVo> menuList = menuService.getMenuList();
        return ResultEntity.ok(menuList);
    }

    @RequestMapping(value = "/getMenuListByUsername",method = RequestMethod.GET)
    public ResultEntity getMenuListByUsername(Authentication authentication){
        log.info("Authentication---->{}", JSON.toJSONString(authentication));
        List<Menu> menuListByUserName = menuService.getMenuListByUserName(authentication.getName());
        return ResultEntity.ok(menuListByUserName);
    }


}
